<?php

/**
 * Class TermDeleteAction
 */
class TermDeleteAction extends CAction
{
	public function run($id)
	{
		if (Yii::app()->getRequest()->getIsPostRequest()) {
			$model = $this->loadModel($id);
			$result = $model->delete();

			if (!isset($_GET['ajax'])) {
				$result && Yii::app()->getUser()->setFlash('success', '术语删除成功');
				$this->getController()->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('view', 'id' => $model->taxonomy_id));
			}
		} else {
			throw new CHttpException(405, '无效的请求，请重试');
		}
	}

	public function loadModel($id)
	{
		if (!$model = Term::model()->findByPk($id)) {
			throw new CHttpException(404, '页面没有找到');
		}
		return $model;
	}
}